getApp().globalData.baseUrl = 'http://open.zhimulp.online/jump';
import api from "@/utils/api.js";
module.exports = {
    httpRequest(url, method, param) {
        var data = param.data;
        var headerParam = {}
        if (url.indexOf("/loginApp") != -1 ) { // 根据自身项目内容 再具体判断
            headerParam = {}
        } else {
            headerParam = {
                'Authorization': token != '' ? uni.getStorageSync('token') : '853004962065444bb0195f6c9ab57644', //检查缓存中有没有token 
                'Content-Type': 'application/json;charset=utf-8'
            }
        } 
        let promise = new Promise(function(resolve, reject) {
            uni.request({
                url: getApp().globalData.baseUrl + url,
                data: data,
                method: method,
                header: headerParam,
                complete: (res) => { //请求完成 
                    uni.hideLoading(); //隐藏加载
                },
                success: (res) => {
                    if (res.data.code == 200) {
                        resolve(res.data);
                    } else if (res.data.code === 401) {
                        reject(res.data.code);
                    } else {
                        uni.showToast({
                            title: res.data.msg,
                            icon: 'none'
                        });
                        reject(res.data.code);
                    }
                },
                fail: (err) => {
                    reject(err);
                }
            });
        });
        return promise;
    }
}